package com.zx.common.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * 基于HandlerExceptionResolver接口的异常处理类
 * 对应spring mvc配置文件 SimpleMappingExceptionResolver
 * @author zx
 *
 */
public class CustomExceptionHandler implements HandlerExceptionResolver {
    
    public static Logger logger = Logger.getLogger("exception");
    
    @Override
    public ModelAndView resolveException(HttpServletRequest request,
            HttpServletResponse response, Object object, Exception exception) {
        
        // ajax 异常
        logger.error("自定义全局异常处理-----start-----:" + exception.getMessage(), exception);
        
//        if(exception instanceof IOException){
//            return new ModelAndView("ioexp");
//        }else if(exception instanceof SQLException){
//            return new ModelAndView("sqlexp");
//        }
        return null;
    }
}
